let parish_mark = [];
let _map=null;
import {
    getParishHomeAll
} from '../../../api/parish';
//isAdd 是否开启添加覆盖物功能
export const parish = async (map, diocese) => {
    _map = map;
    if(parish_mark.length>0){
        _map.remove(parish_mark);
        parish_mark=[];
    }
    let response =await getParishHomeAll({diocese_id:diocese.id});
    let list = response.data.data;
    if (response.status != 200 || !list) return;
    var zoomStyleMapping = {
        5: 0,
        6: 0,
        7: 0,
        8: 0,
        9: 0,
        10: 0,
        11: 0,
        12: 0,
        13: 0,
        14: 0,
        15: 0,
        16: 0,
        17: 0,
        18: 0,
        19: 0,
        20: 0
    }
    for (let i in list) {
        let marker = new AMap.ElasticMarker({
            position: [list[i].lng, list[i].lat],
            zooms: [6, 20],
            styles: [{
                icon: {
                    img: './images/church.png',
                    size: [20, 20], //可见区域的大小
                    // ancher:'center',//锚点
                    ancher:[-45,-80],//锚点
                    fitZoom: 6, //最合适的级别
                    scaleFactor: 2, //地图放大一级的缩放比例系数
                    maxScale: 5, //最大放大比例
                    minScale: 0.6 //最小放大比例
                },
                label:{
                    content:list[i].title,
                    offset:[0,-12],
                    position:'BM',
                    minZoom:7,
                }
            }],
            extData:{parish:list[i]},
            zoomStyleMapping: zoomStyleMapping
        });
        marker.on('click',function(event){
            catholic_show(event);
        })

        parish_mark.push(marker);
        _map.setFitView(parish_mark);
    }
    _map.add(parish_mark);
    // if(isAdd==true){
    //     add_event(adcode);
    // }
}

//教堂信息展示
const catholic_show= (event) =>{
    console.log('parish',event.target.getExtData());
    let parish = event.target.getExtData().parish;
    //构建信息窗体中显示的内容
    let str = `
    <div>
        <h4>${parish.title}</h4>
        <p>地址：${parish.province}${parish.city}${parish.district}${parish.address}</p>
    </div>
    `
    let infoWindow = new AMap.InfoWindow({
        content: str,
        anchor: 'bottom-center',
     });
    infoWindow.open(_map, [parish.lng,parish.lat]);

}

//数据获取
const getList = async (params={}) => {
    
}